<template>
    <div>
        <el-card class="card" shadow="never">
            <template #header>
                窗口设置
            </template>
            <el-col>
                <el-button plain @click="defaultSize">恢复窗口默认尺寸</el-button>
                <el-button plain @click="centerWindow">窗口居中</el-button>
            </el-col>
        </el-card>

        <el-card class="card" shadow="never">
            <template #header>
                下载设置
            </template>

            <el-col>
                <el-text tag="b">下载位置<el-text>（默认将文件下载到该目录中）</el-text></el-text>
                <el-row>
                    <el-col :span="14">
                        <el-tooltip effect="light" :content="download" placement="top">
                            <el-input v-model="download" style="min-width: 300px" placeholder="Please input" disabled />
                        </el-tooltip>
                    </el-col>
                    <el-col :span="5">
                        <el-button plain style="margin-top: 7px;height: 35px;"
                            @click="modifyDownload">更改默认下载位置</el-button>
                    </el-col>
                </el-row>
            </el-col>

            <el-button plain @click="openDownload">打开下载目录</el-button>

        </el-card>

        <!-- <el-card class="card" shadow="never">
            <template #header>
                测试
            </template>
            <el-col>
                <el-button plain @click="test">测试</el-button>
            </el-col>
        </el-card> -->

    </div>
</template>

<script setup lang="ts">
import { ElMessage } from 'element-plus'
import { onMounted, ref } from 'vue';

const download = ref("未获取")

onMounted(
    () => {
        getDownload()
    }
)

const defaultSize = function () {
    window.electronApi.defaultSize()
}
const centerWindow = function () {
    window.electronApi.centerWindow()
}

const modifyDownload = async function () {
    const dirName = await window.electronApi.getDirPath()
    if (dirName === undefined) {
        ElMessage.warning({
            showClose: true,
            message: "没有获取到文件路径！！！"
        })
        return;
    }
    // download.value = dirName
    await window.electronApi.modifySetting('download', dirName)
    getDownload()
}
const getDownload = async function () {
    const userSetting = await window.electronApi.getUserSetting();
    download.value = userSetting.download;
}
const openDownload = function () {
    window.electronApi.open(download.value)
}

const test = async function () {
    const filePath = "D:\\dir\\develop\\HTML+CSS+JS\\Electron\\GTenACG-app\\默认下载\\1话-zip.zip"
    const images = await window.electronApi.getImagesBase64(filePath) as Array;
    console.log(images.length);
}


</script>

<style scoped>
.card {
    /* width: 250px; */
    border: none;
    box-shadow: none;
    margin: 10px;
}

.card * {
    margin: 3px;
}
</style>